package com.learning.spring.ioc.bean.xml.injection;

/**
 * ClassName: BeanInjectionService
 * Description:
 * Date: 2018/7/26 13:17 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class BeanInjectionService {

    private FieldInjection fieldInjection;
    private ConstructorInjection constructorInjection;

    /**
     * 构造函数注入
     *
     * @param constructorInjection
     */
    public BeanInjectionService(ConstructorInjection constructorInjection) {
        this.constructorInjection = constructorInjection;
    }

    void get() {
        fieldInjection.get();
    }

    void done() {
        constructorInjection.done();
    }

    /**
     * 属性注入需要有 setXXX 方法
     *
     * @param fieldInjection
     */
    public void setFieldInjection(FieldInjection fieldInjection) {
        this.fieldInjection = fieldInjection;
    }
}

/**
 * 属性注入的Bean
 */
class FieldInjection {

    public void get() {
        System.out.println("调用 FieldInjection.get() 方法");
    }
}

/**
 * 构造函数注入的 Bean
 */
class ConstructorInjection {

    public void done() {
        System.out.println("调用 ConstructorInjection.done() 方法");
    }
}
